package com.ax.business.common.controller;

import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ax.business.common.service.AssociatorCenterService;
import com.ax.business.common.util.AjaxRes;
import com.ax.business.common.util.Const;
import com.ax.business.common.util.PageUtils;
import com.ax.business.prescription.domain.BaseAssociator;

@Controller
public class AssociatorCenterController {
   
	@Autowired
	AssociatorCenterService associatorCenterService;
	
	/**
	 * 新增会员(模块:会员中心)
	 * 
	 * @param BaseAssociator baseAssociator,HttpServletRequest request
	 *           
	 * @return SUCC
	 */
	@RequestMapping(value="/insertAssociator", method=RequestMethod.GET)
	@ResponseBody
	public AjaxRes insertAssociator(AjaxRes ajaxRes,String phone,Map<String,Object> map,BaseAssociator baseAssociator,HttpServletRequest request){
		try {
		//	String phone = request.getParameter("phone");
			this.associatorCenterService.insertAssociatorSer(baseAssociator,request);
			ajaxRes.setSucceed(Const.SAVE_SUCCEED);
		} catch (Exception e){
			ajaxRes.setFailMsg(e.getMessage());
		}
		return ajaxRes;
	}
	
	/**
	 * 查询会员(模块:会员中心)
	 * 
	 * @param Map<String,Object> map
	 *           
	 * @return PageUtils
	 */
	@RequestMapping("/queryAssociator")
	@ResponseBody
	public AjaxRes queryAssociator(AjaxRes ajaxRes,@RequestParam Map<String, Object> param){
		try {
			PageUtils associators = associatorCenterService.queryAssociatorSer(param);
			ajaxRes.setSucceed(associators,Const.DATA_SUCCEED);
		} catch (Exception e){
			ajaxRes.setFailMsg(e.getMessage());
		}
		return ajaxRes;
	}
	
	/**
	 * 修改会员(模块:会员中心)
	 * 
	 * @param BaseAssociator baseAssociator
	 *           
	 * @return SUCC
	 */
	@RequestMapping("/updateAssociator")
	@ResponseBody
	public AjaxRes updateAssociator(AjaxRes ajaxRes,BaseAssociator baseAssociator){
		try {
			this.associatorCenterService.updateAssociatorSer(baseAssociator);
			ajaxRes.setSucceed(Const.UPDATE_SUCCEED);
		} catch (Exception e){
			ajaxRes.setFailMsg(e.getMessage());
		}
		return ajaxRes;
	}
	
}
